<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>体裁剪</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }


        .box {
            display: grid;
            grid-template-columns: 1fr 1fr;
            margin-bottom: 10px;
            grid-row-gap: 5px;
            align-items: center;
        }

        button {
            padding-left: 20px;
            padding-right: 31px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="edgeWidth">轮廓线宽度</label><input type="number" id="edgeWidth" value="2"
                onchange="setEdgetWidth()">

            <label for="length">长</label><input type="number" id="length" value="19" onchange="updateSize()">
            <label for="width">宽</label><input type="number" id="width" value="19" onchange="updateSize()">
            <label for="height">高</label><input type="number" id="height" value="19" onchange="updateSize()">
        </div>
        <button onclick="resetEdit()">重新选择裁剪位置</button>
        <button onclick="editing()">编辑位置</button>
    </div>
    <script>

        /** -----------------------------------------地球创建----------------------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn(
                [
                    108.960944507017,
                    34.219759660640435,
                    494.9315139069212
                ], [
                263.58063972103986,
                -25.773219891830262,
                0.00003932886719282565
            ], 3
            )
        });
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        //添加3DTileset
        const eS3DTileset = objm.createSceneObjectFromJson({
            "id": "c2c8311e-6e50-47a2-b764-1c82f2d0e256",
            "type": "ES3DTileset",
            "name": "ES3DTileset",
            "allowPicking": true,
            "url": "https://www.earthsdk.com/assets/tileset/osgb_dayanta/tileset.json"
        })


        /**-----------------------------根据类（Class）创建一个ESBoxClipping裁剪对象-------------------------------**/

        let cuttingObject = null;
        // 加载完成
        eS3DTileset.tilesetReady.don((tileset) => {
            cuttingObject = objm.createSceneObject('ESBoxClipping')
            cuttingObject.size = [19, 19, 19]
            //设置裁剪的3dtileset对象的id
            cuttingObject.targetID = eS3DTileset.id;
            // 设置裁剪的基准位置
            cuttingObject.position = [108.9594119, 34.2197855, 471.633]
        })


        // 编辑
        function editing() {
            cuttingObject.editing = true
        }

        // 设置长宽高
        function updateSize() {
            let length = parseInt(document.getElementById("length").value);
            let width = parseInt(document.getElementById("width").value);
            let height = parseInt(document.getElementById("height").value);

            cuttingObject.size = [length, width, height]

        }
        // 设置轮廓线宽度
        function setEdgetWidth() {
            cuttingObject.edgeWidth = Number(document.getElementById('edgeWidth').value)

        }

        // 重新绘制
        function resetEdit() {
            cuttingObject.editing = false
            cuttingObject.position = [0, 0, 0]
            cuttingObject.editing = true
        }
    </script>


</body>

</html>